Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CSS reset, font loading and theme switch outside React to prevent flicker #494

Open
wants to merge 11 commits into
base: development
Choose a base branch
from

Conversation

Danziger
Copy link
Contributor

@Danziger Danziger commented Oct 15, 2024

  • Add different icons for development (plasmo does that automatically but we were overriding that from JS).
  • Move CSS reset and font definitions to a CSS file to remove font loading flicker.
  • Unify theme logic into a single provider and persist background color in localStorage to remove theme flicker.

@Danziger Danziger marked this pull request as draft October 15, 2024 08:24
@Danziger Danziger changed the base branch from production to development October 15, 2024 08:25
@@ -26,10 +26,9 @@ export const Wrapper = styled(motion.div)<{
expanded?: boolean;
}>`
position: relative;
width: ${(props) => (props.responsive ? "100%" : "377.5px")};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .5 seem to fix some rendering issues (underflow) in some cases but cause another issue (overflow) in some other cases. I'd just leave it as 377px which is the actual value this should have everywhere and fix it later by laying out the components differently.

min-height: ${(props) => (props.expanded ? "100vh" : "600px")};
max-height: max-content;
background-color: rgb(${(props) => props.theme.background});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The background is set on the body by the ThemeProvider in the components library, so no need to set it again here.

src/popup.tsx Outdated
</ExpandedViewWrapper>
</HardwareWalletTheme>
</Provider>
<ArConnectThemeProvider>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArConnectThemeProvider replaces Provider + HardwareWalletTheme and used the useTheme hook internally.

@@ -356,7 +372,50 @@ export default function Transaction({ id: rawId, gw, message }: Props) {
{browser.i18n.getMessage("transaction_from")}
</PropertyName>
<PropertyValue>
{formatAddress(transaction.owner.address, 6)}
<div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, it would be better to turn this into a bunch of individual components.

In any case, the reason for this change is that before the UI would only prompt users to add the "to" address as contact. After this change, it would prompt for both "to" and "from", and it would also take into account if an address is yours and display "(you)" next to it.

@Danziger Danziger marked this pull request as ready for review October 15, 2024 10:59
isOpen: boolean;
onClose?: () => void;
children?: React.ReactNode;
}

export default function SliderMenu({
title,
hasNav,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Send view, the last option inside the menus was covered by the bottom navigation.

const themeModifier = hardwareApi ? hardwareThemeModifier : noThemeModifier;

useEffect(() => {
const reducedMotionPreference = window.matchMedia(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this here. It could eventually be added in settings too, just like the system theme can be overridden.

>
<BackButtonIcon />
</BackButton>
{showBack ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional was missing here, so that option did nothing.

</AnimatePresence>
</ButtonAvatar>
</AvatarButton>
{showOptions ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This other one was probably implemented incorrectly and allowOpen (now removed) and showOptions were redundant but not implemented properly. No, the lock screen should only show the title at the top, no back button or wallet selector.

@@ -27,18 +26,6 @@ export default function HistoryProvider({ children }: PropsWithChildren<{}>) {
history.back();
};

// redirect to unlock if decryiption
// key is not available
useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic moved to useSetUp() in ArConnect/src/wallets/index.ts.

@@ -14,32 +14,18 @@ const Route: typeof BaseRoute = ({ path, component, children }) => {
? children(params)
: children;

return (
<AnimatePresence initial={false}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a single AnimatePresence in popup.tsx.

background-color: rgb(${(props) => props.theme.background});
`;

const PageWrapper = styled(Wrapper)`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were some unnecessary containers (HTML) that is now gone, so the HTML structure should look much simpler:

body > #__plasmo > main#Page 

@@ -242,18 +234,23 @@ export default function WalletHeader() {
}
}
];
if (!isExpanded && items.length === 4) {

if (location.pathname === "/popup.html") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full screen version is now loaded from a different HTML file: fullscreen.html, so all these checks are now much simpler and the styling changes require no JS.

// lock wallet and terminate session
async function lockWallet() {
await removeDecryptionKey();
push("/unlock");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a route change anymore. Removing the decryption key makes the root re-render automatically, showing the Unlock screen.


// init popup
useSetUp();
const initialScreenType = useSetUp();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route guarding logic now lives here and doesn't rely on routes to work. That applies to the Unlock screen and an "undefined" state when the app first loads. This will also include a state and UI for the "creating wallet" state of the embedded wallet.

display: none
}
if (initialScreenType === "cover") {
content = <Page />;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty page. Does nothing but wait.

// This can only happen in the embedded wallet:
content = (
<Page>
<p>Generating Wallet...</p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placeholder for the embedded wallet. This does nothing right now, but I'll update it in the other PR once this one is merged.

Copy link
Contributor

@7i7o 7i7o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants